Skip to content

feat(streak): toast the day's streak on the first counted read - #7374

Merged
rebelchris merged 7 commits into
feat/streak-optimistic-viewfrom
feat/streak-daily-celebration
Nov 13, 2026
Merged

rebelchris merged 7 commits into
feat/streak-optimistic-viewfrom
feat/streak-daily-celebration

Conversation

@rebelchris

@rebelchris rebelchris commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Changes

  • Behind streak_daily_celebration: on the first counted read of a local day, a toast "Day {n}! See you tomorrow." with a flame pop (static with reduced motion).
  • Refetch guard: the toast and its milestone check use the refetched current only if its lastViewAt is today in the profile timezone (the same helper as feat(streak): count the read on open and retry dropped views #7373). Otherwise they use the count this read lands on. A refetch that races the API's newView worker therefore can't toast the previous day's number, or toast on a milestone day such as 7 → 8.
  • Skipped on milestone days (Fibonacci, same rule as the API), when streaks are hidden, in the companion, and more than once a day.

Events

Type event_name value
New impression target_type: streak daily celebration, target_id: n

Experiment

Yes: streak_daily_celebration (A/B, default off). Evaluated only for signed-in users who have streaks enabled and settings loaded, outside the companion. #experiments message not posted yet.

Manual Testing

Spec: useViewPost.spec.tsx (including a pre-view refetch on a 7 → 8 milestone day, and no flag evaluation for opted-out users).

Stacked on feat/streak-optimistic-view. Review that one first; this diff shows only this change. Retarget to main once the base merges.

🤖 Generated with Claude Code

Preview domain

https://feat-streak-daily-celebration.preview.app.daily.dev

The milestone modal is the only streak celebration today, and it only
fires on Fibonacci days. The daily moment, the read that actually
extended the streak, had no feedback beyond the rail tile's 700 ms ring
pop, which is off-screen on the post page.

Behind the streak_daily_celebration flag (default off), useViewPost now
shows a "Day {n}! See you tomorrow." toast with the streak flame after
the first counted read of a local day. It reuses the first-view decision
already made in onMutate, waits for the streak refetch and takes n from
the server value, falling back to the count the optimistic update aimed
for when the refetch failed. The flame pops in with a keyframe gated on
motion-safe.

The toast stays away on days the milestone modal takes over: when
alerts.showStreakMilestone is already set, or when the refetched count is
a milestone by the API's own rule (Fibonacci and above 1, mirrored in
lib/streakDailyCelebration.ts), since the alert only reaches the client
on the next boot. It is also skipped when streaks are opted out and in
the extension companion, which has no streak in its cache and would
treat every read as the first of the day.

A per-user localStorage marker (dailydev:streak:celebrated:<userId>)
holding the local date in the profile timezone keeps it to one toast a
day, so an optimistic replay or a second tab does not toast twice. The
toast logs an impression with target type `streak daily celebration` and
the count as target_id.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
daily-webapp Ready Ready Preview Nov 13, 2026 10:47am UTC
storybook Ready Ready Preview Nov 13, 2026 10:47am UTC

Request Review

@rebelchris rebelchris left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One blocker, inherited from the refetch race in #7373 but visible to users here, and one experiment note. The re-run is green.

Reviewed by AI.


const refetched = client.getQueryState<UserStreak>(streakKey);
celebrateStreakDay(
refetched?.status === 'success'

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking: status === 'success' does not mean the refetch saw this read. viewPost only publishes the view, and workers/newView.ts increments the streak asynchronously, so the refetch can return yesterday's current. In that case the toast says "Day N!" when the user is on N+1, and the milestone check is run against the wrong number. On a milestone day (say the user reaches 8), the stale 7 is not a Fibonacci number, so the toast fires, and on the next boot the milestone modal shows 8. That is two celebrations with two different numbers.

Only trust the refetched current if its lastViewAt is today in the user's timezone, and otherwise fall back to context.nextStreak. The same guard fixes the optimistic cache in #7373. Please add a spec where the refetch returns the pre-view streak.

Reviewed by AI.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in f15ba4c, which merges the updated #7373. The refetch helper in onSuccess now resolves with the refetched streak only when hasStreakViewToday passes (the helper from #7373: lastViewAt is today in the profile timezone). The toast gets countedStreak?.current ?? context.nextStreak, so the number and the milestone check use the count this read lands on whenever the refetch is behind. When the optimistic flag is on, the toast also waits for the single retry. Specs: the refetch returns the pre-view 7 on a 7 → 8 day and no toast fires because 8 is a milestone, both with the optimistic flag off and with the flag on where the retry is stale too. Also, a stale refetch on 5 → 6 toasts "Day 6!".

const { logEvent } = useLogContext();
const { value: isEnabled } = useConditionalFeature({
feature: featureStreakDailyCelebration,
shouldEvaluate: !!user && !isCompanion,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking (experiment hygiene): users who opted out of reading streaks are enrolled every time they open a post, but isStreaksEnabled means they can never see the toast, so they dilute both arms. Add isStreaksEnabled to shouldEvaluate (!!user && !isCompanion && isStreaksEnabled). That keeps the user out of the experiment while settings are still loading as well.

Reviewed by AI.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in f15ba4c: shouldEvaluate: !!user && !isCompanion && isStreaksEnabled, where isStreaksEnabled is loadedSettings && !optOutReadingStreak. Specs check that streak_daily_celebration is never evaluated for a user who opted out, or while settings are still loading.

rebelchris and others added 2 commits November 13, 2026 11:39
…ebration

fix(streak): only toast a refetched streak that counts this read

- The toast (and its milestone check) uses the refetched current only
  when its lastViewAt is today in the profile timezone. Otherwise it
  falls back to the count this read lands on (context.nextStreak), so a
  refetch that races the newView worker on 7 -> 8 no longer toasts
  "Day 7!" on a milestone day.
- streak_daily_celebration is only evaluated for users with streaks
  enabled and settings loaded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
rebelchris added a commit that referenced this pull request Nov 13, 2026
…integration

Brings in the stale-refetch guard, same-day replay and error-code changes
from #7373/#7374. Conflicts in getStreak callers resolved by passing both
missedDate/missedDateTimezone and lastViewAt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@rebelchris rebelchris left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-checked at f25b26d. Fixed: the toast and the milestone check now use the refetched count only when it includes this read, and fall back to nextStreak otherwise. streak_daily_celebration is no longer evaluated for opted-out users or while settings are loading. No new findings. CI is green.

Process note: these fixes were made while resolving conflicts in merge commit f15ba4c, not in a commit of their own, so they do not appear in the commit list. Next time, a separate fix commit makes the change easier to follow.

Reviewed by AI.

@rebelchris
rebelchris merged commit f76ef8d into feat/streak-optimistic-view Nov 13, 2026
13 checks passed
@rebelchris
rebelchris deleted the feat/streak-daily-celebration branch November 13, 2026 12:06
rebelchris added a commit that referenced this pull request Nov 13, 2026
…uiet after a gap

The daily toast fell back to current + 1 when the refetch had not caught up.
After a gap the API may reset or freeze the streak, so there is no safe guess:
only a refetch that includes the read is toasted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch was successfully deployed

2 active deployments
Preview – daily-webapp — cfbb5475 Deployed Nov 13, 2026 by vercel[bot]
Preview – storybook — cfbb5475 Deployed Nov 13, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant